<template>
  <div>
    <div class="modal">
      <div class="modal-bg" @click="FloorCloses"></div>
      <div class="pub-w">
        <div class="rele-title" v-show="tianjialouceng">添加楼层<span @click="FloorCloses">X</span>
        </div>
        <div class="rele-title" v-show="xiugailouceng">修改楼层<span @click="FloorCloses">X</span>
        </div>
        <div class="pub-list">
          <div class="pub-li">
            <div class="pub-title">楼层名</div>
            <div class="pub-input"><input type="text" name="" v-model="floortitle"></div>
          </div>
          <div class="pub-li">
            <div class="pub-title">排序值</div>
            <div class="pub-input"><input type="number" name="" v-model="sort"></div>
          </div>
          <div class="pub-li">
            <button v-show="tianjialouceng" @click="tianjiaLC">添加</button>
            <button v-show="xiugailouceng" @click="xiugaiLC">修改</button>
            <button @click="FloorCloses">取消</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script type="text/babel">
  export default {
    props: {
      looklouceng:{
        type:Function
      },
      LDmodal:{
        type:Function
      },
      FloorClose: {
        type: Function
      },
      DYid: {
        type: Number
      },

      LCid:{
        type:Number
      }
    },
    data() {
      return {
        floortitle: '',
        sort: '',
        tianjialouceng:true,
        xiugailouceng:false,
      }
    },
    methods:{
      FloorCloses(){
        this.floortitle = '';
        this.sort = ''
        this.FloorClose()
      },
      TJgoLC(){
        this.tianjialouceng = true;
        this.xiugailouceng = false
      },
      XGgoLC(){
        this.tianjialouceng = false;
        this.xiugailouceng = true
      },
      tianjiaLC(){
        let that = this;
        that.$http.post('/newapi/Premisesfloor/add',{
          premisesunit_id:that.DYid,
          title:that.floortitle,
          sort:that.sort
        }).then(res=>{
          if(res.data.status === 200){
            that.FloorClose();
            that.looklouceng(that.DYid);
            this.$store.state.messageString = res.data.message;
            this.LDmodal();
            that.floortitle = '';
            that.sort = ''
          }else {
            this.$store.state.messageString = res.data.message;
            this.LDmodal();
          }
        }).catch(err=>{
          console.log(err)
        })
      },
      xiugaiLC(){
        let that = this;
        that.$http.post('/newapi/Premisesfloor/add',{
          id:that.$store.state.LCid,
          premisesunit_id:that.DYid,
          title:that.floortitle,
          sort:that.sort
        }).then(res=>{
          if(res.data.status === 200){
            that.FloorClose();
            that.looklouceng(that.DYid);
            that.$store.state.messageString = res.data.message;
            that.LDmodal();
            that.floortitle = '';
            that.sort = ''
          }else {
            that.$store.state.messageString = res.data.message;
            that.LDmodal();
          }
        }).catch(err=>{
          console.log(err)
        })
      },
      gettitle() {
        let that = this;
        that.$http.get('/newapi/Premisesfloor/details', {
          params: {
            id: that.$store.state.LCid
          }
        }).then(res => {
          that.floortitle = res.data.res.title;
          that.sort = res.data.res.sort;
        }).catch(err => {
          console.log(err)
        });
      }
    },
    computed:{
      loucengIDs(){
        return this.loucengID
      }
    }
  }
</script>
<style scoped>
  .pub-li button {
    width: 100px;
    font-size: 1.1em;
    background: #ed7d31;
    color: #ffffff;
    border: none;
    float: left;
    border-radius: 5px;
    line-height: 35px;
  }
  .pub-li button:last-child {
    float: right;
    background: none;
    border: 1px solid #ed7d31;
    color: #ed7d31
  }
  .pub-list {
    width: 100%;
    float: left;
    text-align: center;
    margin-top: 40px;
  }
  .pub-input {
    width: 70%;
    float: left;
  }
  .pub-input input {
    width: 100%;
    line-height: 27px;
    height: 27px;
    float: left;
    box-sizing: border-box;
    border-radius: 5px;
    border: 1px solid #d3d3d3;
  }
  .pub-li {
    margin-top: 20px;
    width: 80%;
    display: inline-block;
  }
  .pub-title {
    width: 30%;
    line-height: 27px;
    text-align: center;
    font-size: 1.1em;
    float: left;
  }
  .pub-w {
    width: 20%;
    left: 40%;
    height: 260px;
    top: 50%;
    overflow: hidden;
    margin-top: -130px;
    background: #ffffff;
    border-radius: 5px;
    position: absolute;
    z-index: 10;
  }
</style>
